﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using Rockfan.Framework;
using Rockfan.Framework.Audio;
using Rockfan.Framework.Entities;
using Rockfan.Framework.Entities.Interfaces;
using Rockfan.Framework.Graphics;

using Player = Rockfan.Framework.PlayerIndex;

namespace Rockfan.Scenes
{
    public sealed class Gamescene : Scene
    {
        Song Song;
        Playerboard Player1;

        Sprite Background;

        public Gamescene()
            : base("GamesceneContent")
        {
            Song = new Song("Song");
        }

        protected override void Intialize()
        {
            var str = new string[]
            {
                @"Content\Songs\Avenged Sevenfold\song.ogg",
                @"Content\Songs\Avenged Sevenfold\guitar.ogg",
                @"Content\Songs\Avenged Sevenfold\rhythm.ogg"               
            };

            var audioTrack = default(AudioTrack);

            for (int i = 0; i < str.Length; i++)
            {
                var track = Song.CreateTrack(str[i]);

                if (i != 0 && track != null)
                    track.Volume = 50.0f;

                if (i == 1)
                    audioTrack = track;

                track.Delay = 1.875f;
            }

            var chart = Chart.Load(@"Content\Songs\Avenged Sevenfold");

            Background = new Sprite(Theme.GetTextureFromName("DefaultStage").Texture);
            Background.XScale = Camera.GetXScaleAtDistance(0.0f);
            Background.YScale = Camera.GetYScaleAtDistance(0.0f);

            Player1 = new Guitarboard(Player.One, chart, audioTrack);
            Player1.LoadContent();

            Add(Background);
            Add(Player1);

            base.Intialize();
        }

        public override void Activity(bool isFirstCall)
        {
            if (isFirstCall)
            {
                Theme.PlaySoundFromName("BoardStart");
                Player1.Start();
                Song.Play();
            }
        }

        public override void Load()
        {
            
            base.Load();
        }

        public override Task LoadAsync(ProgressChanged callback)
        {
            
            
            return base.LoadAsync(callback);
        }

        protected override void Destroy()
        {
            
            
        }
    }
}
